

function initCompany($scope){
    $scope.Addrs = {'address': {"selProvince":"", "selCity":"", "selCounty":""} };
    loadAddrs($scope, $scope.Addrs);
    initCols($scope);
    $scope.getNewCompany = function(){
        $scope.line = {
            id:-1,
            companyName: '',
            address: '',
            editUser:'',
            telephone:'',
            other:'',
        };
        initAddr($scope, "", "", "");
        $scope.cols[0].disabled = false;
    }
};


function initCols($scope){
    $scope.cols = [];
    $scope.cols.push({'name':'公司', 'field': 'companyName', 'type':'text', 'disabled':true });
    $scope.cols.push({'name':'地址', 'field': 'address', 'type':'address' });
    $scope.cols.push({'name':'负责人', 'field': 'editUser', 'type':'text', 'disabled':false });
    $scope.cols.push({'name':'联系电话', 'field': 'telephone', 'type':'text', 'disabled':false });
    $scope.cols.push({'name':'备注', 'field': 'other', 'type':'text', 'disabled':false });
}

function initAddr($scope, province, city, county){
    $scope.Addrs['address'].selProvince = province;
    $scope.Addrs['address'].selCity = city;
    $scope.Addrs['address'].selCounty = county;
    
    $scope.updateAddrs("address");     //// 地址组件赋值手动赋值完
}

//// 提交公司信息
function setCompany($scope, callback) {
    $scope.line['province'] = $scope.Addrs['address'].selProvince;
    $scope.line['city'] = $scope.Addrs['address'].selCity;
    $scope.line['county'] = $scope.Addrs['address'].selCounty;
    $scope.line['module'] = 'admin'; 
    var cpName = $scope.line.companyName;
    var dt = {'company':cpName, cp:JSON.stringify($scope.line)};
    
    ajaxData('set_company_info', dt, function(rst){
        if($scope.line.id==-1){
            if(rst.data!=-1){
                $scope.line['id'] = rst.data;
            }else{
                alert("修改失败，请检查资料");
                return;
            }
        }else{
            if(rst.data!=0){
                alert("修改失败，请检查资料");
                return;
            }    
        }
        
        if(callback)callback(rst.data, cpName + " - " + $scope.line['province']);
        $("#myModal1").modal('hide');
    });
};